📜 Tipiṭaka CSCD XML to HTML Conversion in Termux
Batch transformation using xsltproc and Bash automation

---

#### 🛠️ Step 1: Program Installation (Termux Setup)

Install required packages:

```bash
pkg update
pkg upgrade
pkg install libxml2 libxslt which xsltproc
```

Verify installation:

```bash
which xsltproc
```

Expected output:  
/data/data/com.termux/files/usr/bin/xsltproc

---

#### 🗂️ Step 2: Directory Structure Setup

Project layout:

```bash
~/tipitaka/
├── tipitaka-deva.xsl        # Your XSL stylesheet
├── convert_batch.sh         # Bash script for batch conversion
├── odia/                    # Folder containing CSCD XML corpus
│   ├── vin12t.nrf2.xml
│   └── ...
└── html/                    # Output folder for HTML files
```
---

#### 📄 Step 3: Bash Script Creation

Save the following as convert_batch.sh in ~/tipitaka/:

```bash

#!/data/data/com.termux/files/usr/bin/bash

XSL_FILE="./tipitaka-odia.xsl"
XML_DIR="./odia"
OUT_DIR="./html"

echo "📁 Ensuring output directory exists: $OUT_DIR"
mkdir -p "$OUT_DIR"

# If a file is passed as argument, process only that file
if [[ -n "$1" ]]; then
    xml_file="$1"
    # Ensure the file is inside XML_DIR
    if [[ "$xml_file" == "$XML_DIR"* && -f "$xml_file" ]]; then
        rel_path="${xml_file#$XML_DIR/}"
        base_name="${rel_path%.xml}"
        out_path="$OUT_DIR/${base_name}.html"
        mkdir -p "$(dirname "$out_path")"
        echo "➡ Converting: $rel_path → ${base_name}.html"
        xsltproc "$XSL_FILE" "$xml_file" > "$out_path"
        echo "≈ File converted and stored at '$out_path'"
    else
        echo "∥∥ Error: File must be inside '$XML_DIR' and must exist."
        exit 1
    fi
else
    # No argument: process all files recursively
    find "$XML_DIR" -type f -name "*.xml" | while read -r xml_file; do
        rel_path="${xml_file#$XML_DIR/}"
        base_name="${rel_path%.xml}"
        out_path="$OUT_DIR/${base_name}.html"
        mkdir -p "$(dirname "$out_path")"
        echo "➡ Converting: $rel_path → ${base_name}.html"
        xsltproc "$XSL_FILE" "$xml_file" > "$out_path"
    done
    echo "⊷ All files converted and stored under '$OUT_DIR/'"
fi
```

Make executable:

```bash
chmod +x convert_batch.sh
```

---

#### 🚀 Step 4: Execute the Script

for batch conversion Run from inside ~/tipitaka/:

```bash
./convert_batch.sh
```
for single file conversion 

```bash
./convert.sh ./odia/sutta/dn1.xml
```
All XML files in odia/ will be processed and saved as HTML in html/.

---

#### 🧠 Achievements

- Avoided dependencies on Java/Python; fully shell-based
- Established a modular pipeline ready for Odia integration
- Prepped for future font ligature, transliteration, and metadata enrichment

---

